## Understanding Public Attitudes toward Restrictive Voting Laws
## Katie Clayton  
## Step 5: Exploratory analysis of main results among white respondents only
## Last updated: June 8, 2023

# Initial settings --------------------------------------------------------

rm(list = ls())
library(tidyverse)
library(margins)

# Main results among white respondents only -------------------------------

df <- read.csv("output/cleaned_dataset.csv") %>%
  mutate(group = factor(group, levels = c("control","harm","boost"))) %>% 
  filter(race == 1) ## filter to white respondents only

mod1 <- estimatr::lm_robust(support_law~group*rep.dum,df)

mod2 <- estimatr::lm_robust(election.trust~group*rep.dum,df)

mod3 <- estimatr::lm_robust(emo.anger~group*rep.dum,df)

mod4 <- estimatr::lm_robust(lottery_3~group*rep.dum,df)

# Create Table B2 ----------------------------------------------------------

texreg::texreg(mod1, digits = 3)
texreg::texreg(mod2, digits = 3)
texreg::texreg(mod3, digits = 3)

me1.dem
me2.dem
me3.dem

me1.rep
me2.rep
me3.rep

library(multcomp)

lincom1.party1 <- summary(glht(mod1, linfct = c("groupharm:rep.dum + groupharm = 0")))
lincom1.party2 <- summary(glht(mod1, linfct = c("groupboost:rep.dum + groupboost = 0")))
list1.party <- c(coef(lincom1.party1), sqrt(vcov(lincom1.party1)), coef(lincom1.party2), sqrt(vcov(lincom1.party2)))
list1.party

lincom2.party1 <- summary(glht(mod2, linfct = c("groupharm:rep.dum + groupharm = 0")))
lincom2.party2 <- summary(glht(mod2, linfct = c("groupboost:rep.dum + groupboost = 0")))
list2.party <- c(coef(lincom2.party1), sqrt(vcov(lincom2.party1)), coef(lincom2.party2), sqrt(vcov(lincom2.party2)))
list2.party

lincom3.party1 <- summary(glht(mod3, linfct = c("groupharm:rep.dum + groupharm = 0")))
lincom3.party2 <- summary(glht(mod3, linfct = c("groupboost:rep.dum + groupboost = 0")))
list3.party <- c(coef(lincom3.party1), sqrt(vcov(lincom3.party1)), coef(lincom3.party2), sqrt(vcov(lincom3.party2)))
list3.party

lincom4.party1 <- summary(glht(mod4, linfct = c("groupharm:rep.dum + groupharm = 0")))
lincom4.party2 <- summary(glht(mod4, linfct = c("groupboost:rep.dum + groupboost = 0")))
list4.party <- c(coef(lincom4.party1), sqrt(vcov(lincom4.party1)), coef(lincom4.party2), sqrt(vcov(lincom4.party2)))
list4.party


